class Solution {
public:
    int NumberOf1Between1AndN_Solution(int n) {
        if(n<1)
            return 0;
        int sum=0;    //和
        int base=1;    //每位的权值
        int round=n;
        while(round>0){
            int weight=round%10;//当前位的值
            round/=10;
            sum+=round*base;
            if(weight==1)
                sum+=(n%base)+1;//前一位的值+1(加的是最后一位为0的情况)
            else if(weight>1)
                sum+=base;
            base*=10;
        }
        return sum;
    }
};